package com.maixun.lib_comment.extends

import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade

/**
 * 作者：Lmoumou
 * 时间：2020/7/29 11:23
 */

/**
 * ImageView使用Glide加载图片的扩展方法
 * */
fun ImageView.loadPicture(
    path: String,
    placeholderPic: Int? = null,
    errorPic: Int? = null,
    fallBackPic: Int? = null
) {
    val builder = Glide.with(this).load(path)
    if (placeholderPic != null)
        builder.placeholder(placeholderPic)

    if (errorPic != null)
        builder.error(errorPic)

    if (fallBackPic != null)
        builder.fallback(fallBackPic)

    builder.transition(withCrossFade())
        .diskCacheStrategy(DiskCacheStrategy.ALL)
        .into(this)
}